<?php

namespace App\Http\Requests\Admin\Panx\StaffManage;

use App\Http\Requests\ApiRequest;
use App\Models\Admin\PanxAdmin;
use App\Models\Panx\Sex;
use App\Services\Locale\Language;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

/**
 * @property string name
 * @property string account
 * @property string password
 * @property string phone
 * @property int sex
 * @property string born_at
 * @property string role_name
 */
class PanxStaffStoreRequest extends ApiRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $data = [
            'name'      => 'required|string|max:'.self::MAX_STRING,
            'email'     => 'required|string|email|unique:panx_admins,email|max:'.self::MAX_STRING,
            'account'   => 'required|string|unique:panx_admins,account|max:'.self::MAX_STRING,
            'password'  => 'required|string|min:6|max:'.self::MAX_STRING,
            'sex'       => ['required', 'int', Rule::in(Sex::allIds())],
            'born_at'   => 'nullable|date',
            'role_name' => 'required|string|max:'.self::MAX_STRING,
            'phone'     => ['required', 'string', 'max:'.self::MAX_STRING],
        ];

//        if (app()->getLocale() === Language::ZH_CN) {
//            $data['phone'] = ['required', 'regex:/^1[34578][0-9]{9}$|^((0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/'];
//        } else {
//            $data['phone'] = ['required', 'string'];
//        }

        return $data;
    }

    /**
     * @return array
     */
//    public function messages()
//    {
//        return [
//            'name.*'      => ':attribute必须是字符串',
//            'email.*'     => ':attribute必须是合法的邮箱',
//            'account.*'   => ':attribute不能与现有账号重复',
//            'password.*'  => ':attribute长度必须是6个字符',
//            'phone.*'     => ':attribute必须是合法手机号',
//            'sex.*'       => ':attribute必须是1或2',
//            'born_at.*'   => ':attribute必须是合法的日期',
//            'role_name.*' => ':attribute必须是字符串',
//        ];
//    }
//
//    /**
//     * @return array
//     */
//    public function attributes()
//    {
//        return [
//            'name'      => '管理员名称',
//            'account'   => '管理员账号',
//            'email'     => '管理员邮箱',
//            'password'  => '密码',
//            'phone'     => '手机号',
//            'sex'       => '性别',
//            'born_at'   => '出生日期',
//            'role_name' => '角色',
//        ];
//    }
}
